//
//  SiterUserNetManager.m
//  AFNetworking
//
//  Created by Henry on 2023/1/10.
//

#import "SiterUserNetManager.h"
#import "SiterAPI.h"
#import "NVLogManager.h"

@implementation SiterUserNetManager

//获取账号资料
+ (void) getProfile:(void(^)(id,NSError *,NSError *)) handler{

    return [self HttpGET:[NSString stringWithFormat:@"%@/sso/baseinfo",[[Siter sharedInstance] getDomain]] parameters:nil completionHandler:^(id responseObj, NSError *error1,NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//修改账号资料
+ (void) modifyProfile:(NSDictionary *)params handle:(void(^)(id,NSError *,NSError *)) handler{

    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/user/profile",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//修改免打扰状态
+ (void) modifyDisturbState:(NSString *)status handle:(void(^)(id,NSError *,NSError *)) handler{
    
    NSDictionary *params = @{@"notDisturb":status};
    
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/sso/updateDisturbStat",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//修改账号密码
+ (void) modifyPassword:(NSDictionary *)params handle:(void(^)(id,NSError *,NSError *)) handler{

    return [self HttpPOST:[NSString stringWithFormat:@"%@/changePassword",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj,NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//绑定FCM推送接口
+ (void) bindPushTag:(NSString *)register_token handle:(void(^)(id,NSError *,NSError *)) handler{
    NSArray *appLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
    NSString *languageName = [appLanguages objectAtIndex:0];

     if(![languageName containsString:@"zh"]){
         languageName = @"en";
     }else{
         languageName = @"zh";
     }
    NSDictionary *params = @{@"register_token":register_token,@"language":languageName};
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/user/bindPushTag",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//解绑FCM推送接口
+ (void) unBindPushTag:(NSString *)register_token handle:(void(^)(id,NSError *,NSError *)) handler{
    NSUserDefaults *config = [NSUserDefaults standardUserDefaults];
    [config setObject:register_token forKey:@"register_token"];
    [config synchronize];
    NSDictionary *params = @{@"register_token":register_token};
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/user/unbindPushTag",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//获取用户反馈类型列表
+ (void) getFeedBackTypeList:(void(^)(id,NSError *,NSError *)) handler{

    
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/fbtype/getList",[[Siter sharedInstance] getDomain]] parameters:@{} completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取用户反馈信息列表
+ (void) getFeedBackList:(void(^)(id,NSError *,NSError *)) handler{

    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/fb/getByuserid",[[Siter sharedInstance] getDomain]] parameters:@{} completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取用户反馈详情
+ (void) getFeedBackDetail:(NSString *)feedId handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *params = @{@"id":feedId};
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/fb/getByfdid",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}




//创建用户反馈信息
+ (void) submitFeedBack:(NSString *)content withThingName:(NSString *)thingName withFileUrl:(NSString *)fileUrl withFrequency:(NSString *)frequency withType:(NSString *)fbType withHandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{
      @"fbComment": content,
      @"fbDevice": thingName,
      @"fbFile": fileUrl,
      @"fbFrequency": frequency,
      @"fbType": fbType
    };
    
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/fb/create",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取用户反馈详情
+ (void)replyToFeedbackDetail:(NSString *)feedId withContent:(NSString *)content handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *params = @{@"id":feedId,@"fbComment":content};
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/fb/createResponse",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//结束反馈
+ (void)endFeedbackDetail:(NSString *)feedId handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *params = @{@"id":feedId};
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/fb/updateFinish",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}



//获取消息中心列表
+ (void) getMessageCenterList:(NSNumber *)pageNum withPageSize:(NSNumber *)pageSize withType:(NSString *)type withHandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{
      @"pageNum": pageNum,
      @"pageSize": pageSize,
      @"type":type
    };
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/messageCenter/list",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//注销账号
+ (void) unRegister:(void(^)(id,NSError *,NSError *)) handler{
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/sso/cancel",[[Siter sharedInstance] getDomain]] parameters:@{} completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//获取code(音箱用)
+ (void)getCode:(NSString *)redirectUri handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *param = @{
                             @"redirectUri" :redirectUri
                             };
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/thirdAuth/getAuthCode",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj,  NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

+ (void)getweather:(double)lat withLon:(double)lon handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *param = @{@"lat" :@(lat),@"lon": @(lon)};
    NSString *host = [[Siter sharedInstance] getDomain];
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/weather",host] parameters:param completionHandler:^(id responseObj,  NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

+ (void)enableAwsAlexa:(NSString *)awscode handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *param = @{@"awsCode":awscode,
                            @"redirectUri":[[Siter sharedInstance] getRedirectURL],
                            @"skillId":[[Siter sharedInstance] getAlexaSkillId]};
    NSString *host = [[Siter sharedInstance] getDomain];
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/alexaSkill/enableAndLink",host] parameters:param completionHandler:^(id responseObj,  NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


+ (void)getAwsAlexaStatus:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *param = @{@"skillId":[[Siter sharedInstance] getAlexaSkillId]};
    NSString *host = [[Siter sharedInstance] getDomain];
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/alexaSkill/getLinkAndSkillStatus",host] parameters:param completionHandler:^(id responseObj,  NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


+ (void)disableAwsAlexa:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *param = @{@"skillId":[[Siter sharedInstance] getAlexaSkillId]};
    NSString *host = [[Siter sharedInstance] getDomain];
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/alexaSkill/disableSkillAndUnLink",host] parameters:param completionHandler:^(id responseObj,  NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取谷歌home授权状态
+ (void)getGoogleHomeStatus:(void(^)(id,NSError *,NSError *)) handler{


    NSDictionary *param = @{@"authType":@"GOOGLEHOME"};
    NSString *host = [[Siter sharedInstance] getDomain];
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/thirdAuth/list",host] parameters:param completionHandler:^(id responseObj,  NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//谷歌home授权code获取之前调用
+ (void)createGoogleHomeAuth:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *param = @{@"authType":@"GOOGLEHOME"};
    NSString *host = [[Siter sharedInstance] getDomain];
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/thirdAuth/create",host] parameters:param completionHandler:^(id responseObj,  NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}



//取消谷歌home关联接口
+ (void)disableGoogleHome:(void(^)(id,NSError *,NSError *)) handler{
    NSString *host = [[Siter sharedInstance] getDomain];
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/googlehome/deleteAgentId",host] parameters:@{} completionHandler:^(id responseObj,  NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取未读消息数量
+ (void) getUnReadNum:(NSString *)type  withHandler:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *param = nil;
    if(type==nil){
        param = @{};
    }else{
        param = @{@"type":type};
    }
    
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/messageCenter/unReadNum",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//设置全部已读
+ (void) setAllRead:(void(^)(id,NSError *,NSError *)) handler{

    
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/messageCenter/allRead",[[Siter sharedInstance] getDomain]] parameters:@{} completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//设置多条消息已读
+ (void) setMessageRead:(NSArray *)messageIds withHandler:(void(^)(id,NSError *,NSError *)) handler{

    
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/messageCenter/idRead",[[Siter sharedInstance] getDomain]] parameters:messageIds completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//上传日志
+ (void) uploadConfigLog:(NSString *)thingName withContent:(NSString *)content withHandler:(void(^)(id,NSError *,NSError *)) handler{

    
    
    NSDictionary *param = @{@"thingName":thingName==nil?@"":thingName,
                            @"title":@"iOS connected failed",
                            @"content":content
    };
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/appLog/create",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取设备分享列表
+ (void) getShareMemberList:(NSString *)thingName withHandler:(void(^)(id,NSError *,NSError *)) handler{

    
    
    NSDictionary *param = @{@"thingName":thingName};
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/bind/getShareMemberInfo",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//创建设备分享
+ (void) createDeviceShare:(NSString *)thingName withUsername:(NSString *)username withHandler:(void(^)(id,NSError *,NSError *)) handler{

    
    
    NSDictionary *param = @{@"thingName":thingName,@"addUserName":username};
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/deviceShare/preCreate",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//设备分享同意或者拒绝
+ (void) operateDeviceShare:(NSString *)messageId withUsername:(NSString *)option withHandler:(void(^)(id,NSError *,NSError *)) handler{

    
    
    NSDictionary *param = @{@"messageId":messageId,@"action":option};
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/deviceShare/handleInvite",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//设备校验已分享人数
+ (void) getShareCount:(NSString *)thingName withHandler:(void(^)(id,NSError *,NSError *)) handler{

    
    
    NSDictionary *param = @{@"thingName":thingName};
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/deviceShare/count",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//主动扫码分享
+ (void) deviceShareRequest:(NSString *)thingName withShareKey:(NSString *)shareKey withHandler:(void(^)(id,NSError *,NSError *)) handler{

    
    
    NSDictionary *param = @{@"thingName":thingName,@"shareKey":shareKey};
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/deviceShare/request",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}



//获取设备的被分享人员
+ (void) getShareMemberInfo:(NSString *)thingName withHandler:(void(^)(id,NSError *,NSError *)) handler{

    
    
    NSDictionary *param = @{@"thingName":thingName};
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/bind/getShareMemberInfo",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//取消设备分享人员
+ (void) deviceShareCancel:(NSString *)thingName withUsername:(NSString *)username withHandler:(void(^)(id,NSError *,NSError *)) handler{

    
    
    NSDictionary *param = @{@"thingName":thingName,@"addUserName":username};
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/deviceShare/cancel",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//删除设备分享人员记录
+ (void) deviceShareDelete:(NSString *)thingName withUsername:(NSString *)username withId:(NSNumber *)messageId withHandler:(void(^)(id,NSError *,NSError *)) handler{

    
    
    NSDictionary *param = @{@"thingName":thingName,@"addUserName":username,@"id":messageId};
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/deviceShare/delete",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//获取意见反馈未读消息数量
+ (void) getFbUnReadNum:(void(^)(id,NSError *,NSError *)) handler{
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/fb/getUnreadNumByuserid",[[Siter sharedInstance] getDomain]] parameters:@{} completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

@end
